home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0041_Transparent PutImage.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  2KB  |  61 lines

  1. {
  2. From: SEAN PALMER
  3. Subj: transparent putimage
  4. }
  5.  
  6. Procedure PutImg(x,y : integer;Var Img);
  7. type
  8.  AList = array[1..$FFFF] of Byte; {1-based arrays are slower than 0-based}
  9. var
  10.  APtr : AList;                   {I found a very fast way to do this: WITH}
  11.  j,i,Width,Height,Counter : Word;
  12. begin
  13.  Aptr:=@Img;
  14.  Width:=(Aptr] SHL 8) + Aptr]+1;  {these +1's that 1-based arrays }
  15.  Height:=(Aptr] SHL 8) + Aptr]+1;  { require make for slower code}
  16.  Counter:=5;
  17.  For j:=y to (y+height-1) do begin  {try pre-calculating the offset instead}
  18.   for i:=x to (x+width-1) do begin
  19.    case AptrCounter] of          {CASE is probably not the way to do this}
  20.     0:; (* do nothing *)
  21.     else _mcgaScreen[j,i]:=AptrCounter]; (* plot it *)
  22.     end;
  23.    Inc(Counter);
  24.    end;
  25.   end;
  26.  end;
  27.  
  28. ok, here's my try:
  29.  
  30. type pWord=word;
  31.  
  32. procedure putImg(x,y:integer;var image);
  33. var
  34.  anImg:record img:array[0..$FFF7]of byte; end absolute image;
  35.  aScrn:record scrn:array[0..$FFF7]of byte; end absolute $A000:0000;
  36.  width,height,counter,offs,src:word;
  37. begin
  38.  width:=pWord(@anImg[0])
  39.  height:=pWord(@anImg[2])
  40.  offs:=y*320+x;
  41.  src:=4;   {skip width, height}
  42.  with aScrn,anImg do repeat
  43.   counter:=width;
  44.   repeat
  45.    if img[src]<>0 then scrn[offs]:=img[src];
  46.    inc(src);
  47.    inc(offs);
  48.    dec(counter);
  49.    until counter=0;
  50.   inc(offs,320-width);
  51.   dec(height);
  52.   until height=0;
  53.  end;
  54.  
  55.  
  56. Those arrays-pretending-to-be-records above so they'll work with the WITH
  57. statement should end up making BP keep the address in registers, making it
  58. faster. In any case it won't be slower than yours. I'd appreciate you
  59. timing them and letting me know the results. Actually, let me know if it
  60. even compiles and works... 8)
  61.